package com.zut.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zut.mapper.ParentsMapper;
import com.zut.mapper.ProductMapper;
import com.zut.pojo.Parents;
import com.zut.pojo.Product;
import com.zut.pojo.Teacher;
import com.zut.service.ProductService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.beans.PropertyDescriptor;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author product
 * @since 2021-05-31
 */
@Service
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements ProductService {

    @Resource
    ProductMapper productMapper;

    @Resource
    ParentsMapper parentsMapper;

    @Resource
    ProductService productService;

    @Override
    public boolean addPro(Product product) {
        boolean i= productService.save(product);
        System.out.println("i===" + i);
        return  i;
    }

    @Override
    public boolean buyPro(Integer parid, Integer proid) {
        int ProHour= productMapper.selectById(proid).getProhour();
        QueryWrapper<Parents> wrapper = new QueryWrapper<>();
        wrapper.eq("parid",parid);
        Parents parents=parentsMapper.selectById(parid);
        parents.setParhour(parents.getParhour()+ProHour);
        parentsMapper.update(parents,wrapper);
        return false;
    }

    @Override
    public boolean updatePro(Product product) {
        boolean flag=productService.updateById(product);
        return flag;
    }

    @Override
    public int deletePro(Integer proid) {
        productMapper.deleteById(proid);
        return 1;
    }

    //按id查找产品
    @Override
    public Product selectProductById(Integer proid) {
        QueryWrapper<Product> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("proid",proid);
        Product product = productMapper.selectOne(queryWrapper);
        return product;
    }

    //管理⚪模糊查询产品
    @Override
    public List<Product> seapro(String msg) {
        QueryWrapper<Product> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("proid", msg)
                .or().like("proprice",msg)
                .or().like("prohour",msg)
                .or().like("proname",msg)
                .or().like("prourl",msg)
        ;
        List<Product> productList = productMapper.selectList(queryWrapper);
        return productList;
    }
}
